<!DOCTYPE html>
<html style="width:100%;height:100%;">
<head lang="en">
    <meta charset="UTF-8">
    <title>微信用户列表</title>
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/color.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/icon.css">
    <link type="text/css" rel="stylesheet" href="/resources/css/yidong.css">
    <script type="text/javascript" src="/resources/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/jquery.cookie.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var pageSize = $.cookie("pageSize");
            $.cookie("pageNo", 1, {expires:1});
            if(!pageSize) {
                $.cookie("pageSize", 10, {expires:1});
            }
            loadWechatUserList($.cookie("pageSize"), $.cookie("pageNo"), null, 'appId='+$.cookie("appId"));
            //分页操作
            var pager = $('#wechatUserList').datagrid('getPager');
            if(pager){
                $(pager).pagination({
                    onSelectPage:function(pageNumber, pageSize){
                        $.cookie("pageNo", pageNumber, {expires:1});
                        loadWechatUserList(pageSize, pageNumber, null, $('#searchForm').serialize());
                    },
                    onRefresh:function(pageNumber, pageSize){
                        loadWechatUserList(pageSize, pageNumber, null, $('#searchForm').serialize());
                    },
                    onChangePageSize:function(pageSize){
                        $.cookie("pageSize", pageSize, {expires:1});
                        loadWechatUserList(pageSize, 1, null, $('#searchForm').serialize());
                    }
                })
            }
        });

        function searchList() {
            loadWechatUserList($.cookie("pageSize"), 1, null, $('#searchForm').serialize())
        }

        function loadWechatUserList(pageSize, pageNo, successFun, condition) {
            var data = 'pageSize='+pageSize+'&pageNo='+pageNo;
            if(condition) {
                data = data + '&' + condition;
            }
            restClient('/rest/wechat/user/list', function(data){
                $('#wechatUserList').datagrid("loadData", data);
                if(successFun) successFun();
            }, data);
        }

        function formatSubscribeTime(value, row, index) {
            if(row.subscribe_time) {
                return new Date(row.subscribe_time).Format("yyyy-MM-dd hh:mm:ss");
            }
        }

        function formatStatus(value, row, index) {
            if(row.status != null) {
                if(row.status == 0) {
                    return '正在关注';
                } else if(row.status == -2 || row.status == -1) {
                    return '取消关注';
                } else {
                    return row.status;
                }
            }
        }
    </script>
</head>
<body onload="isLogon();" style="width:100%;height:100%;margin: 0;">
<table id="wechatUserList" class="easyui-datagrid" style="width:100%;height:100%;"
       toolbar="#toolbar" pagination="true"
       data-options="pageList:[10,15,20],pageSize:$.cookie('pageSize') ? $.cookie('pageSize') : 10"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="appId" width="100">AppId</th>
        <th field="openId" width="100">用户Id</th>
        <th field="nickName" width="100">用户名</th>
        <th field="subscribe_time" width="80" data-options="formatter:formatSubscribeTime">关注时间</th>
        <th field="status" width="50" data-options="formatter:formatStatus">状态</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <form id="searchForm">
        AppId: <input class="easyui-combobox" id="appId" name="appId" style="width: 200px;"
                      data-options="valueField:'appId', textField:'description', formatter:formatAppId, editable:false">
        用户状态:
        <select class="easyui-combobox" name="status" data-options="editable:false">
            <option value="all">所有</option>
            <option value="0">正在关注</option>
            <option value="-2">取消关注</option>
        </select>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="searchList()">搜索</a>
    </form>
</div>

<script type="text/javascript">
    loadAppIdCombobox($('#appId'), true);
</script>
</body>
</html>